package com.hm.myapplication;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
       private final List<String> mData;

       public static class ViewHolder extends RecyclerView.ViewHolder {
           public TextView textView;
           public ViewHolder(View v) {
               super(v);
               textView = v.findViewById(R.id.text_view);
           }
       }

       public MyAdapter(List<String> data) {
           mData = data;
       }

       @NonNull
       @Override
       public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
           View v = LayoutInflater.from(parent.getContext())
                   .inflate(R.layout.item_layout, parent, false);
           return new ViewHolder(v);
       }

       @Override
       public void onBindViewHolder(ViewHolder holder, int position) {
           holder.textView.setText(mData.get(position));
       }

       @Override
       public int getItemCount() {
           return mData.size();
       }
   }
   